package pl.edu.mimuw.irs.rcp.controller.handler;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CommandStack;

import pl.edu.mimuw.irs.core.model.design.resource.IMember;
import pl.edu.mimuw.irs.rcp.controller.editor.util.IMemberWrapper;
import pl.edu.mimuw.irs.rcp.controller.editor.util.command.DeleteMemberCommand;
import pl.edu.mimuw.irs.rcp.controller.editor.workflow.handler.AbstractCommandStackSelectionHandler;

public class DeleteMemberHandler extends AbstractCommandStackSelectionHandler {

	// *** Attributes
	
	// *** Methods

	@Override
	protected Object execute(ExecutionEvent event, CommandStack stack,
			Object[] selection) throws ExecutionException {
		for (Object object : selection) {
			if (object instanceof IMemberWrapper) {
				IMemberWrapper wrapper = (IMemberWrapper) object;
				IMember member = wrapper.getMember();
				Command command = new DeleteMemberCommand(member);
				stack.execute(command);
			} else if (object instanceof IMember) {
				IMember member = (IMember) object;
				Command command = new DeleteMemberCommand(member);
				stack.execute(command);
			}
		}
		
		return null;
	}
}
